Skip to content

feature: add copy-as-code-snippet for requests on the Send page#243

Merged
pimterry merged 3 commits into
httptoolkit:mainfrom
komen205:send-copy-as-code-snippet
Jun 26, 2026
Merged

feature: add copy-as-code-snippet for requests on the Send page#243
pimterry merged 3 commits into
httptoolkit:mainfrom
komen205:send-copy-as-code-snippet

Conversation

@komen205

Copy link
Copy Markdown
Contributor

What

Adds the ability to copy a request as a code snippet directly from the Send page, while editing it — without having to send it first and export from the View page.

A new copy button sits in the Send request line (between the URL input and the Send button). Clicking it opens a menu mirroring the View page's export context menu:

  • "Copy as X Snippet" shortcut for the preferred format, when one is set
  • A "Copy as Code Snippet" submenu with all available httpsnippet targets

Picking a format from the submenu copies the snippet and updates the persisted preferred format (uiStore.exportSnippetFormat), same as the View page behaviour.

How

  • generateHarRequestFromRequestData() in har.ts builds an ExtendedHarRequest from not-yet-sent request data (decoded body, raw headers, HTTP/1.1), reusing the existing cookie parsing, postData generation, and non-UTF8 body fallback.
  • generateCodeSnippetFromRequestInput() in export.ts feeds that through the same HAR-simplification + httpsnippet conversion as the existing View-page path, which was refactored into a shared helper so both stay in sync (content-length/content-encoding/H2 pseudo-header dropping etc).
  • Snippet options are Pro-gated, matching the View page's export menu.
  • Invalid in-progress URLs fail with an alert rather than copying a broken snippet, and the button is disabled while the URL is empty.

Tests

Added test/unit/model/ui/export.spec.ts covering snippet generation from request inputs: simple GET, POST with body (content-length dropped), content-encoding dropped with decoded body used, and a clear failure for invalid URLs. Full unit suite passes (894 tests).

🤖 Generated with Claude Code

@komen205

komen205 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Looks like this
image

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "http://android.httptoolkit.tech/config");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Host: android.httptoolkit.tech");
headers = curl_slist_append(headers, "Connection: Keep-Alive");
headers = curl_slist_append(headers, "Accept-Encoding: gzip");
headers = curl_slist_append(headers, "User-Agent: okhttp/4.11.0");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_ACCEPT_ENCODING, "");

CURLcode ret = curl_easy_perform(hnd);

@komen205 komen205 changed the title Add copy-as-code-snippet for requests on the Send page feature: add copy-as-code-snippet for requests on the Send page Jun 11, 2026
: undefined;

const menuItems: Array<ContextMenuItem<void>> = [
...(!isPaidUser ? [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is worth to keep, the whole feature is already gated anyway.

@komen205

Copy link
Copy Markdown
Contributor Author

@pimterry wyt about this? Is this something you'd like to add? I'd love to have this feature. Lmk your thoughts and I will resolve the conflicts.
I have a few more features I want to add, but would be nice to have this one merged first!

@pimterry

Copy link
Copy Markdown
Member

Hi @komen205 sorry for the delay! I have seen this, I'm totally on board with the goal, I've just been quite busy elsewhere for a week, and still trying think through the UI design for this. It depends how we want to expose this, and what other similar features we might want in future... There's other options to consider like a menu bar or similar, or footer, or dropdown button attached to the Send button, etc. I'll find time for a proper review and confirm a plan early this week.

Out of interest, what are the other features you're interested in? Anything else on the Send page that might be related to this?

@komen205

Copy link
Copy Markdown
Contributor Author

@pimterry Let me know!

The feature I was talking about is: #249 I opened now the PR as draft so you can see. I still have to look more into that code and match it with the coding standards of the repo.

komen205 and others added 3 commits June 26, 2026 18:15
Adds a copy button to the Send request line that opens a menu of code
snippet formats, mirroring the View page's export context menu. The
snippet is generated directly from the in-progress request input, so
requests can be exported as code while editing, before they're sent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pimterry pimterry force-pushed the send-copy-as-code-snippet branch from 0b0a498 to 3be07ed Compare June 26, 2026 16:27
@pimterry

Copy link
Copy Markdown
Member

Right, now sorted, sorry for the delay. I've pushed a couple of extra changes: fixing the positioning so it follows the button not the mouse (more like a menu) and simplify the HAR code so we don't have two separate paths there. And then a force push to rebase since there were conflicts here with some other changes.

Now merged! Thanks for contributing 😄. This will go live in just a few minutes.

By the way, in case you're not aware, HTTP Toolkit Pro is free for all contributors to all https://github.com/httptoolkit repos. If that would be useful, just let me know your email (either here or by sending a message to opensource @ httptoolkit.com) and I'll set you up with an account.

@pimterry pimterry merged commit cc63e76 into httptoolkit:main Jun 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants